<?php

namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\App;
use util\Excel;
use think\facade\Db;
use think\cache\driver\Redis;

/**
 * Sitereport控制器
 */
class Sitereport extends AdminBase
{

    protected $model = null;

    protected $validate = null;

    protected $relationSearch = false;

    protected $zfreight_addition_w = 0;
    protected $total_pricex = 0;
    protected $freightx = 0;
    protected $materialx = 0;

    protected $arr_sku = [];
    protected $arr_sku_include = [];
    protected $arr_sku_notinclude = [];

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\Sitereport();

        $this->validate = \app\admin\validate\Sitereport::class;
    }

    /**
     * 列表
     */
    public function index()
    {

        list($limit, $where, $sortArr) = $this->buildTableParames();

        $where2 = array();
        $filters = $this->request->get('filter', '{}');
        $filters = json_decode($filters, true);
        //筛选日期
        if(!empty($filters['month']) && isset($filters['month'])){
            $where2['timedate'] = strtotime($filters['month']);
        }else{
            $where2['timedate'] = strtotime(date('Y-m', strtotime('first day of last month')));
        }
        if(!empty($filters['site_id']) && isset($filters['site_id'])){
            $where2['site_id'] = $filters['site_id'];
        }
        
        $list = $this->model
            ->where($where2)
            ->order('timedate desc')
            ->paginate($limit);
        $ztotal_price = $this->model
            ->field('sum(total_price) as total_price,sum(freight) as freight,sum(material) as material,sum(total_tip_received) as total_tip_received')
            ->where($where2)
            ->find();
            
        //查看当月汇率
        if(!empty($filters['month']) && isset($filters['month'])){
            $b_time = strtotime($filters['month']);
            $exchange_time = date("Y-m", $b_time);

                $exchange = table('exchange')
                    ->where('currency','USD')
                    ->where('date',$exchange_time)
                    ->find();
                if(empty($exchange)){
                    $exchange = table('exchange')
                    ->where('currency','USD')
                    ->order('date desc')
                    ->find();
                }

                $exchange_eur = table('exchange')
                    ->where('currency','EUR')
                    ->where('date',$exchange_time)
                    ->find();
                if(empty($exchange_eur)){
                    $exchange_eur = table('exchange')
                    ->where('currency','EUR')
                    ->order('date desc')
                    ->find();
                }
            
        }else{
            $exchange = table('exchange')
                ->where('currency','USD')
                ->order('date desc')
                ->find();
            $exchange_eur = table('exchange')
                ->where('currency','EUR')
                ->order('date desc')
                ->find();
        }
        
        $lists = $list->items();
        foreach ($lists as $k => $v) {
            $site = table('site')
                ->where(['id' => $v['site_id']])->find();
            if (!empty($site)) {
                $lists[$k]['site_name'] = $site['site_name'];
            } else {
                $lists[$k]['site_name'] = '未知';
            }
            $lists[$k]['timedate'] = date('Y-m', $v['timedate']);
        }
        
        $data = [
            'code' => 1,
            'msg' => '',
            'count' => $list->total(),
            'data' => $lists,
            'ztotal_price' => !empty($ztotal_price['total_price']) ? $ztotal_price['total_price'] : 0,
            'freightx' => !empty($ztotal_price['freight']) ? $ztotal_price['freight'] : 0,
            'materialx' => !empty($ztotal_price['material']) ? $ztotal_price['material'] : 0,
            'zfreight_addition_w' => !empty($ztotal_price['total_tip_received']) ? $ztotal_price['total_tip_received'] : 0,
        ];

        return json($data);
    }

    /**
     * 导出
     */
    public function download_sales()
    {
        $redis = new Redis();
        $header = array();
        $header[] = ['日期', 'created_at'];
        $header[] = ['订单号', 'name'];
        $header[] = ['原销售额', 'total_price'];
        $header[] = ['物流￥', 'freight'];
        $header[] = ['采购￥', 'material'];
        $header[] = ['币种', 'currency'];
        $header[] = ['支付渠道', 'gateway'];
        $header[] = ['支付状态', 'financial_status'];
        $header[] = ['收货状态', 'fulfillment_status'];
        $header[] = ['标签', 'tags'];
        $header[] = ['争议状态', 'dispute_status'];
        $header[] = ['争议金额', 'dispute_cost'];
        $header[] = ['备注', 'remarks'];

        $header[] = ['现销售额$', 'total_pricex'];
        $header[] = ['现运费￥', 'freightx'];
        $header[] = ['现采购￥', 'materialx'];
        $header[] = ['退款金额', 'refunded'];

        $header[] = ['运费是否估算', 'estimate_freight'];
        $header[] = ['采购是否估算', 'estimate_material'];

        $header[] = ['物流加成费￥', 'freight_additionx'];
        $header[] = ['sku明细', 'skuinfo'];
        $header[] = ['spu明细', 'skuinfo2'];
        $tableName = '当月订单明细';
        $fileName = "export_" . $tableName . "_" . time();

        $get = $this->request->get();
        $shopify_personreport = table('shopify_sitereport')
            ->where('id',$get['id'])
            ->find();
        $site_id = $shopify_personreport['site_id'];
        $start_time = $shopify_personreport['timedate'];
        $end_time = date("Y-m-d", $start_time);
        $end_time = strtotime(date("Y-m-d", strtotime("$end_time +1 month")));
        //计算业绩
        $order_where[]  = ['created_at', '>=', $start_time];
        $order_where[]  = ['created_at', '<=', $end_time];
        $order_where[]  = ['site_id', '=', $site_id];
        $order_where[] = ['financial_status', 'in', ['paid','partially_paid','partially_refunded','refunded']];
        
        $lists = Db::name('order')
            ->field("
                created_at,
                name,
                total_price,
                freight,
                material,
                currency,
                gateway,
                financial_status,
                fulfillment_status,
                tags,
                dispute_status,
                dispute_cost,
                istransfer as estimate_freight,
                refunded,
                skuinfo,
                skuinfo2,
                ismaterial as estimate_material
            ")
            ->where($order_where)
            ->select()
            ->toarray();
            
        if(!empty($lists)){
            foreach ($lists as $k=>$v) {
                $v = $this->handling_performance($v,$shopify_personreport['timedate']);
                $lists[$k] = $v;
                $lists[$k]['created_at'] = date('Y-m-d H:i:s', $v['created_at']);
            }
        }
        //附加表
        $lists = $this->processing_tables_w($lists,$start_time);

        //更新
        $sitereport['total_price'] = $this->total_pricex;
        $sitereport['freight'] = $this->freightx;
        $sitereport['material'] = $this->materialx;
        $sitereport['total_tip_received'] = $this->zfreight_addition_w;
        if(!empty($sitereport)){
            table('shopify_sitereport')
                ->where('id',$get['id'])
                ->update($sitereport); 
        }
        // return true;
        return Excel::exportData($lists, $header, $fileName, 'xlsx');
    }

    /**
     * 处理业绩规则
     */
    public function handling_performance($item,$timedate)
    {
        if(!empty($item['estimate_freight'])){
            // * 0未对接成功
            // * 1对接成功
            // * 2估算物流成功
            switch ($item['estimate_freight']) {
                case '0':
                    $item['estimate_freight'] = '等待估算';
                    // $item['freightx'] = 0;
                    break;
                case '1':
                    $item['estimate_freight'] = '真实运费';
                    break;
                case '2':
                    $item['estimate_freight'] = '估算';
                    // $item['freightx'] = 0;
                    break;
                default:
                    $item['estimate_freight'] = '未知';
                    // $item['freightx'] = 0;
            }
            // * ismaterial 采购
            // * 0未对接成功
            // * 1对接成功
            // * 2预估
            switch ($item['estimate_material']) {
                case '0':
                    $item['estimate_material'] = '等待估算';
                    // $item['materialx'] = 0;
                    break;
                case '1':
                    $item['estimate_material'] = '真实采购费';
                    break;
                case '2':
                    $item['estimate_material'] = '估算';
                    // $item['materialx'] = 0;
                    break;
                default:
                    $item['estimate_material'] = '未知';
                    // $item['materialx'] = 0;
            }
        }
        // $item['skuinfo2'] = "bra89*1,bra89*2,sock03*2";
        //spu统计
        // if (!empty($item['skuinfo2'])) {
        //     //拆分规则
        //     $pos1 = strpos($item['skuinfo2'], ',');
        //     if ($pos1 !== false) {
        //         $sku = explode(',', $item['skuinfo2']);
        //         if(!empty($sku)){
        //             foreach ($sku as $k1=>$v1) {
        //                 $spus = explode('*', $v1);
        //                 if(isset($this->arr_sku[$spus[0]]) && !empty($this->arr_sku[$spus[0]])){
        //                     $this->arr_sku[$spus[0]] += (int)$spus[1];
        //                 }else{
        //                     $this->arr_sku[$spus[0]] = (int)$spus[1];
        //                 }
        //                 //区分未计入跟已计入
        //                 if($item['fulfillment_status'] !== 'fulfilled'){
        //                     if(isset($this->arr_sku_notinclude[$spus[0]]) && !empty($this->arr_sku_notinclude[$spus[0]])){
        //                         $this->arr_sku_notinclude[$spus[0]] += (int)$spus[1];
        //                     }else{
        //                         $this->arr_sku_notinclude[$spus[0]] = (int)$spus[1];
        //                     }
        //                 }else{
        //                     if(isset($this->arr_sku_include[$spus[0]]) && !empty($this->arr_sku_include[$spus[0]])){
        //                         $this->arr_sku_include[$spus[0]] += (int)$spus[1];
        //                     }else{
        //                         $this->arr_sku_include[$spus[0]] = (int)$spus[1];
        //                     }
        //                 }
        //             }
        //         }
        //     } else {
        //         $pos1 = strpos($item['skuinfo2'], '*');
        //         if ($pos1 !== false) {
        //             $spus = explode('*', $item['skuinfo2']);
        //             if(isset($this->arr_sku[$spus[0]]) && !empty($this->arr_sku[$spus[0]])){
        //                 $this->arr_sku[$spus[0]] += (int)$spus[1];
        //             }else{
        //                 $this->arr_sku[$spus[0]] = (int)$spus[1];
        //             }
        //             //区分未计入跟已计入
        //             if($item['fulfillment_status'] !== 'fulfilled'){
        //                 if(isset($this->arr_sku_notinclude[$spus[0]]) && !empty($this->arr_sku_notinclude[$spus[0]])){
        //                     $this->arr_sku_notinclude[$spus[0]] += (int)$spus[1];
        //                 }else{
        //                     $this->arr_sku_notinclude[$spus[0]] = (int)$spus[1];
        //                 }
        //             }else{
        //                 if(isset($this->arr_sku_include[$spus[0]]) && !empty($this->arr_sku_include[$spus[0]])){
        //                     $this->arr_sku_include[$spus[0]] += (int)$spus[1];
        //                 }else{
        //                     $this->arr_sku_include[$spus[0]] = (int)$spus[1];
        //                 }
        //             }
        //         }
        //     }
        // }
        
        $item['total_pricex'] = 0;
        $item['freightx'] = 0;
        $item['materialx'] = 0;
        $item['remarks'] = '';
        if($item['tags'] == '暂无'){
            $item['tags'] = '';
        }
        switch ($item['dispute_status']) {
            case '0':
                $item['dispute_status'] = '正常';
                $item['total_pricex'] = (float)number_format((float)$item['total_price'] - $item['refunded'], 3, '.', '');
                $item['freightx'] = $item['freight'];
                $item['materialx'] = $item['material'];
                break;
            case '1':
                $item['dispute_status'] = '有争议';
                $item['total_pricex'] = 0;
                $item['freightx'] = $item['freight'];
                $item['materialx'] = $item['material'];
                $item['remarks'] = '争议订单不算销售额';
                break;
            default:
                $item['dispute_status'] = '未知';
        }
        if($item['dispute_status'] == '有争议' && $item['dispute_cost'] <= 0.01){
            //默认争议费
            switch ($item['gateway']) {
                case 'paypal':
                    $item['dispute_cost'] = 16;
                    break;
                case 'stripe':
                    $item['dispute_cost'] = 18;
                    break;
                default:
                    $item['dispute_cost'] = 16;
            }
        }
        if($item['financial_status'] == 'paid' && $item['fulfillment_status'] !== 'fulfilled'){
            $item['total_pricex'] = 0;
            $item['freightx'] = 0;
            $item['materialx'] = 0;
            $item['remarks'] = $item['remarks'].'|已付款(未发货)不算业绩';
            $item['estimate_freight'] = '';
            $item['estimate_material'] = '';
        }
        if($item['financial_status'] == 'refunded' && $item['fulfillment_status'] !== 'fulfilled'){
            $item['total_pricex'] = 0;
            $item['freightx'] = 0;
            $item['materialx'] = 0;
            $item['remarks'] = $item['remarks'].'|已退款(未发货)不算业绩';
            $item['estimate_freight'] = '';
            $item['estimate_material'] = '';
        }
        if($item['financial_status'] == 'refunded' && $item['fulfillment_status'] == 'fulfilled'){
            $item['total_pricex'] = 0;
            $item['freightx'] = $item['freight'];
            $item['materialx'] = $item['material'];
            $item['remarks'] = $item['remarks'].'|已退款(已发货)不算销售额';
        }

        // $redis = new Redis();
        // $exchange_time = date("Y-m", $timedate);

        // $exchange = $redis->get('exchangerate_site');
        // if(empty($exchange)){
        //     $exchange = table('exchange')
        //         ->where('currency','USD')
        //         ->where('date',$exchange_time)
        //         ->find();
        //     $redis->set('exchangerate_site', $exchange, 60 * 60 * 24 );
        // }
        // $exchange_eur = $redis->get('exchangerate_eur_site');
        // if(empty($exchange_eur)){
        //     $exchange_eur = table('exchange')
        //         ->where('currency','EUR')
        //         ->where('date',$exchange_time)
        //         ->find();
        //     $redis->set('exchangerate_eur_site', $exchange_eur, 60 * 60 * 24 );
        // }
        // $exchange_mxn = $redis->get('exchangerate_mxn_site');
        // if(empty($exchange_mxn)){
        //     $exchange_mxn = table('exchange')
        //         ->where('currency','MXN')
        //         ->where('date',$exchange_time)
        //         ->find();
        //     $redis->set('exchangerate_mxn_site', $exchange_mxn, 60 * 60 * 24 );
        // }
        
        // if($item['freightx'] >= 0.001){
        //     $item['freightx'] = (float)number_format((float)$item['freightx'] / (float)$exchange['proportion'], 3, '.', '');
        // }
        // if($item['materialx'] >= 0.001){
        //     $item['materialx'] = (float)number_format((float)$item['materialx'] / (float)$exchange['proportion'], 3, '.', '');
        // }
        
        //物流加成费
        $item['freight_additionx'] = 0;
        if($item['fulfillment_status'] == 'fulfilled'){
            $this->zfreight_addition_w += 2;
            $item['freight_additionx'] = 2;
        }

        //总和
        
        // if($item['currency'] == 'EUR'){
        //     $item['total_pricex'] = (float)number_format((float)$item['total_pricex'], 3, '.', '');
        //     $item['total_pricex'] = (float)number_format((float)$item['total_pricex'] * (float)$exchange_eur['proportion'] / (float)$exchange['proportion'], 3, '.', '');
        // }
        // if($item['currency'] == 'USD'){
        //     $item['total_pricex'] = (float)number_format((float)$item['total_pricex'], 3, '.', '');
        // }
        // if($item['currency'] == 'MXN'){
        //     $item['total_pricex'] = (float)number_format((float)$item['total_pricex'], 3, '.', '');
        //     $item['total_pricex'] = (float)number_format((float)$item['total_pricex'] * (float)$exchange_mxn['proportion'] / (float)$exchange['proportion'], 3, '.', '');
        // }

        $this->total_pricex = (float)number_format((float)$item['total_pricex'] + $this->total_pricex, 3, '.', '');
        $this->freightx = (float)number_format((float)$item['freightx'] + $this->freightx, 3, '.', '');
        $this->materialx = (float)number_format((float)$item['materialx'] + $this->materialx, 3, '.', '');

        return $item;
    }


    /**
    * 方法详情
    * @param array params
    */
    public function processing_tables_w($list,$start_time)
    {
        $list_sumb = array();
        $list_sumb['created_at'] = '';
        $list_sumb['name'] = '';
        $list_sumb['total_price'] = '';
        $list_sumb['freight'] = '';
        $list_sumb['material'] = '';
        $list_sumb['currency'] = '';
        $list_sumb['gateway'] = '';
        $list_sumb['financial_status'] = '';
        $list_sumb['fulfillment_status'] = '';
        $list_sumb['tags'] = '';
        $list_sumb['dispute_status'] = '';
        $list_sumb['dispute_cost'] = '';
        $list_sumb['remarks'] = '';
        $list_sumb['total_pricex'] = '';
        $list_sumb['freightx'] = '';
        $list_sumb['materialx'] = '';
        $list_sumb['refunded'] = '';
        $list_sumb['estimate_freight'] = '';
        $list_sumb['estimate_material'] = '';
        $list_sumb['freight_additionx'] = '';
        $list_sumb['skuinfo'] = '';
        $list_sumb['skuinfo2'] = '';
        $list[] = $list_sumb;

        $list[] = $list_sumb;
        $list_sum_total = array();
        $list_sum_total['created_at'] = '统计';
        $list_sum_total['name'] = '现销售额$';
        $list_sum_total['total_price'] = '现运费￥';
        $list_sum_total['freight'] = '现采购￥';
        $list_sum_total['material'] = '物流加成费￥';
        $list_sum_total['currency'] = '';
        $list_sum_total['gateway'] = '';
        $list_sum_total['financial_status'] = '';
        $list_sum_total['fulfillment_status'] = '';
        $list_sum_total['tags'] = '';
        $list_sum_total['dispute_status'] = '';
        $list_sum_total['dispute_cost'] = '';
        $list_sum_total['remarks'] = '';
        $list_sum_total['total_pricex'] = '';
        $list_sum_total['freightx'] = '';
        $list_sum_total['materialx'] = '';
        $list_sum_total['refunded'] = '';
        $list_sum_total['estimate_freight'] = '';
        $list_sum_total['estimate_material'] = '';
        $list_sum_total['freight_additionx'] = '';
        $list_sum_total['skuinfo'] = '';
        $list_sum_total['skuinfo2'] = '';
        $list[] = $list_sum_total;

        $list_sum_total = array();
        $list_sum_total['created_at'] = '';
        $list_sum_total['name'] = $this->total_pricex;
        $list_sum_total['total_price'] = $this->freightx;
        $list_sum_total['freight'] = $this->materialx;
        $list_sum_total['material'] = $this->zfreight_addition_w;
        $list_sum_total['currency'] = '';
        $list_sum_total['gateway'] = '';
        $list_sum_total['financial_status'] = '';
        $list_sum_total['fulfillment_status'] = '';
        $list_sum_total['tags'] = '';
        $list_sum_total['dispute_status'] = '';
        $list_sum_total['dispute_cost'] = '';
        $list_sum_total['remarks'] = '';
        $list_sum_total['total_pricex'] = '';
        $list_sum_total['freightx'] = '';
        $list_sum_total['materialx'] = '';
        $list_sum_total['refunded'] = '';
        $list_sum_total['estimate_freight'] = '';
        $list_sum_total['estimate_material'] = '';
        $list_sum_total['freight_additionx'] = '';
        $list_sum_total['skuinfo'] = '';
        $list_sum_total['skuinfo2'] = '';
        $list[] = $list_sum_total;

        $list[] = $list_sumb;

        $list_sum2 = array();
        $list_sum2['created_at'] = '类型';
        $list_sum2['name'] = '货号';
        $list_sum2['total_price'] = '件数';
        $list_sum2['freight'] = '单价';
        $list_sum2['material'] = '成本￥';
        $list_sum2['currency'] = '';
        $list_sum2['gateway'] = '';
        $list_sum2['financial_status'] = '';
        $list_sum2['fulfillment_status'] = '';
        $list_sum2['tags'] = '';
        $list_sum2['dispute_status'] = '';
        $list_sum2['dispute_cost'] = '';
        $list_sum2['remarks'] = '';
        $list_sum2['total_pricex'] = '';
        $list_sum2['freightx'] = '';
        $list_sum2['materialx'] = '';
        $list_sum2['refunded'] = '';
        $list_sum2['estimate_freight'] = '';
        $list_sum2['estimate_material'] = '';
        $list_sum2['freight_additionx'] = '';
        $list_sum2['skuinfo'] = '';
        $list_sum2['skuinfo2'] = '';
        $list[] = $list_sum2;
        
        //sku统计
        $list_sum3 = array();
        $list_sum3['created_at'] = '';
        $list_sum3['name'] = '';
        $list_sum3['total_price'] = '';
        $list_sum3['freight'] = '单价';
        $list_sum3['material'] = '成本￥';
        $list_sum3['currency'] = '';
        $list_sum3['gateway'] = '';
        $list_sum3['financial_status'] = '';
        $list_sum3['fulfillment_status'] = '';
        $list_sum3['tags'] = '';
        $list_sum3['dispute_status'] = '';
        $list_sum3['dispute_cost'] = '';
        $list_sum3['remarks'] = '';
        $list_sum3['total_pricex'] = '';
        $list_sum3['freightx'] = '';
        $list_sum3['materialx'] = '';
        $list_sum3['refunded'] = '';
        $list_sum3['estimate_freight'] = '';
        $list_sum3['estimate_material'] = '';
        $list_sum3['freight_additionx'] = '';
        $list_sum3['skuinfo'] = '';
        $list_sum3['skuinfo2'] = '';

        if(!empty($this->arr_sku_include)){
            $total_price_Total_include = 0;
            $material_Total_include = 0;
            foreach ($this->arr_sku_include as $key => $value) {
                $list_sum3['created_at'] = '已计入';
                $list_sum3['name'] = $key;
                $list_sum3['total_price'] = $value;
                $CalculateCosts = $this->CalculateCosts($key,$value,$start_time);
                $list_sum3['freight'] = $CalculateCosts['UnitPrice'];
                $list_sum3['material'] = $CalculateCosts['Cost'];
                $list[] = $list_sum3;

                $total_price_Total_include += $list_sum3['total_price'];
                $material_Total_include += $list_sum3['material'];
            }
            //已计入总和
            $list_sum3['created_at'] = '已计入总计';
            $list_sum3['name'] = "";
            $list_sum3['total_price'] = $total_price_Total_include;
            $list_sum3['freight'] = "";
            $list_sum3['material'] = $material_Total_include;
            $list[] = $list_sum3;
            $list[] = $list_sumb;
        }
        
        if(!empty($this->arr_sku_notinclude)){
            foreach ($this->arr_sku_notinclude as $key => $value) {
                $list_sum3['created_at'] = '未计入';
                $list_sum3['name'] = $key;
                $list_sum3['total_price'] = $value;
                $CalculateCosts = $this->CalculateCosts($key,$value,$start_time);
                $list_sum3['freight'] = $CalculateCosts['UnitPrice'];
                $list_sum3['material'] = $CalculateCosts['Cost'];
                $list[] = $list_sum3;
            }
            $list[] = $list_sumb;
        }
        if(!empty($this->arr_sku)){
            $total_price_Total = 0;
            $material_Total = 0;
            foreach ($this->arr_sku as $key => $value) {  
                $list_sum3['created_at'] = '总共';
                $list_sum3['name'] = $key;
                $list_sum3['total_price'] = $value;
                $CalculateCosts = $this->CalculateCosts($key,$value,$start_time);
                $list_sum3['freight'] = $CalculateCosts['UnitPrice'];
                $list_sum3['material'] = $CalculateCosts['Cost'];
                $list[] = $list_sum3;

                $total_price_Total += $list_sum3['total_price'];
                $material_Total += $list_sum3['material'];

            }
            //总和
            $list_sum3['created_at'] = '总计';
            $list_sum3['name'] = "";
            $list_sum3['total_price'] = $total_price_Total;
            $list_sum3['freight'] = "";
            $list_sum3['material'] = $material_Total;
            $list[] = $list_sum3;

            $list[] = $list_sumb;
        }

        return $list;
    }

    /**
    * 方法详情
    * @param array params
    */
    public function CalculateCosts($key,$value,$start_time)
    {
        $CalculateCosts['UnitPrice'] = 0;
        $CalculateCosts['Cost'] = 0;
        
        $redis = new Redis();
        $info = $redis->get('CalculateCosts'.$key."".$start_time);
        if(empty($info)){
            $info = table('procurement_cost')
                ->where('number', $key)
                ->where('timedate', $start_time)
                ->find();
            $redis->set('CalculateCosts'.$key."".$start_time, $info, 60*60);
        }
        if(!empty($info)){
            $CalculateCosts['UnitPrice'] = $info['material'];
            $CalculateCosts['Cost'] = $info['material'] * $value;
        }
        return $CalculateCosts;
    }
    
}